package RayTracing;

import java.util.ArrayList;

public class Ray {


	//########################## Global Variables  ###################################
	double[] P0 = new double[3];
	double t;
	double[] V = new double[3];
	double[] P = new double[3];
	Shape bestShape;

	//########################## Constructors ###################################
	
	public Ray(){
		if (RayTracer.SHOW_LOG){ System.out.println("In Ray Empty Constructor");}
		
	}
	
	public Ray(double[] P0, double[] V){
		if (RayTracer.SHOW_LOG){ System.out.println("In Ray Constructor");}
		this.P0 = P0;
		this.V = V;
	}
	
	public Ray(double[] P0, double t, double[] V){
		if (RayTracer.SHOW_LOG){ System.out.println("In Ray Constructor");}
		this.P0 = P0;
		this.t = t;
		this.V = V;
	}
	
	//########################## Ray Functions ###################################
	
	public void getHit(ArrayList<Shape> shpList){
		setT(Double.POSITIVE_INFINITY);
		double t;
		for (Shape currSph : shpList){
			t = currSph.getT(this);
			if ((t > 0.0) && (t <= getT())){
				setT(t);
				setBestShape(currSph);
			}
		}
	}
	
	public void constructRayThorughPixel(int i, int j, Camera cam){
		setV(cam.IJ2los(i, j));
	}
	
	//########################## Getters and Setters ###################################
	
	public double[] getP0() {
		return P0;
	}

	public void setP0(double[] p0) {
		P0 = p0;
	}

	
	public Shape getBestShape() {
		return bestShape;
	}
	
	public double getT() {
		return t;
	}

	public void setT(double t) {
		this.t = t;
	}


	public double[] getV() {
		return V;
	}

	public void setV(double[] v) {
		V = v;
	}

	
	public double[] getP() {
		P = Vector.computeVectorAddition(getP0(), Vector.multiplyVectorbyScalar(getV(), getT()));
		return P;
	}

	public void setP(double[] p) {
		P = p;
	}

	
	public void setBestShape(Shape bestShape) {
		this.bestShape = bestShape;
	}


}
